import React, { Component } from 'react'
import styles from "../assets/styles/model.module.css"
//引入验证的规则
import PropTypes from "prop-types"

class Model extends Component {
    // state = {
    //     visible: true
    // }

    closeModel = ()=>{
        console.log(this);
        console.log(this.props);
        // this.props.modelVisible = false
        this.props.close()
    }
    
    render() {
        // const { visible } = this.state
        const {modelVisible,username} = this.props
        if (modelVisible) {
            return (
                <div className={styles.modelOption}>
                    {/* <p>添加优惠券</p> */}
                    <div className={styles.modelContent}>
                        <h3>添加优惠券--{username}</h3>
                        {/* 你要显示的模态框内容 */}
                        {this.props.children}
                        {/* end */}
                        <button onClick={this.closeModel}>关闭</button>
                    </div>
                </div>
            )
        }else{
            return null
        }
    }
}

// Model.propTypes = {
//     modelVisible:PropTypes.bool.isRequired,
//     min:PropTypes.number.isRequired
// }
Model.defaultProps = {
    modelVisible:false,
    username:"xiaowang"
}
export default Model